﻿@model Proggy.Web.Cms.Core.PropertyTypes.CharLimitedTextString
@{
    // get config object
    var configObject = Model.GetConfigObject<CharLimitedTextStringConfigObject>();

    // get area id
    var areaId = Model.GetUniqueElementId("", "");
    
    // get remaining
    var rmn = configObject.Limit > 0 ? 
        (configObject.Limit - Model.SavedValue.Length).ToString() : "Unlimited";

    var minRmn =
        (Model.SavedValue.Length >= configObject.Minimum ? "0" : (configObject.Minimum - Model.SavedValue.Length).ToString());

    // add js / css
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.DragAndDrop.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Css/CharLimitedTextString.css", BackEndContentType.Stylesheet);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/proggy.corepropertytypes.clts.js", BackEndContentType.JavaScript);
    Html.RenderBackEndContentForLightboxPartial();
    
}
<div id="@areaId" class="clts">
    <div class="clts-limit">
        Characters allowed remaining: <span class="clts-limit-rmn">@rmn</span>
    </div>
    <div class="clts-min">
        Characters required remaining: <span class="clts-min-rmn">@minRmn</span>
    </div>
    <div class="clts-text left-indent">
        @if (configObject.Multiline)
        { 
            @:@Html.TextArea(Model.PropertyNameStart + ".SavedValue", Model.SavedValue, new { @class = "proggy-textarea proggy-textarea-large" })
        }
        else
        {
            @:@Html.TextBox(Model.PropertyNameStart + ".SavedValue", Model.SavedValue, new { @class = "proggy-textbox proggy-textbox-wide" })
        }
    </div>
</div>
<script type="text/javascript">

    //
    Proggy.Static.WaitForTypesToRegister(function () {

        // create object
        var clts = new Proggy.CorePropertyTypes.Clts();

        // init
        clts.Init("@(areaId)", @(configObject.Limit), @(configObject.Minimum));

    });
</script>
